<?php


namespace app\store\model;
use app\common\model\Lottery as LotteryModel;
use think\Db;
class Lottery extends LotteryModel
{
    /**
     * 获取大转盘列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList()
    {
        return $this->where('is_delete', '=', 0)
            ->order(['create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
    }
    public function addLottery($data, $jpData){
        $data['wxapp_id'] = self::$wxapp_id;
        $data['start_time'] = strtotime($data['start_time']);
        $data['end_time'] = strtotime($data['end_time']);

        $this->allowField(true)->save($data);
        for($i = 0; $i < count($jpData); $i++){
            $jp = [];
            if($i == 0){
                $jp['start_angle'] = 288;
                $jp['end_angle'] = 360;
                $jp['angle'] = 324;
            }elseif($i == 1){
                $jp['start_angle'] = 216;
                $jp['end_angle'] = 288;
                $jp['angle'] = 252;
            }elseif($i == 2){
                $jp['start_angle'] = 144;
                $jp['end_angle'] = 216;
                $jp['angle'] = 180;
            }elseif($i == 3){
                $jp['start_angle'] = 72;
                $jp['end_angle'] = 144;
                $jp['angle'] = 108;
            }elseif($i == 4){
                $jp['start_angle'] = 1;
                $jp['end_angle'] = 72;
                $jp['angle'] = 36;
            }
            $jp['lottery_id'] = $this['lottery_id'];
            $jp['types'] = $jpData[$i]['types'];
            $jp['index'] = $i;
            if($jpData[$i]['types'] == 20) {
                $jp['points'] = $jpData[$i]['points'];
            }
            if($jpData[$i]['types'] == 30) {
                $jp['coupon_id'] = $jpData[$i]['coupon_id'];
            }
            if($jpData[$i]['types'] == 40) {
                $jp['content'] = $jpData[$i]['content'];
            }
            Db::name("lottery_jiangpin")->insert($jp);
        }
        return $this['lottery_id'];
    }
}